﻿using System;
using System.Linq;
using GdHotel.Data.Interfaces;
using UniqueTechnologies.Data.Interfaces;

namespace GdHotel.Data.Repositories
{
    public class NotesRepository : INotesRepository
    {
        private GdHotelEntities entities = new GdHotelEntities();

        public IQueryable<Note> FindAll()
        {
            return entities.Notes.AsQueryable();
        }

        public IQueryable<Note> FindAllByLang(Language lang)
        {
            return entities.Notes.Where(n => n.LanguageId == lang.Id).AsQueryable();
        }

        public Note GetById(Int32 id)
        {
            return entities.Notes.SingleOrDefault(n => n.Id == id);
        }

        public void Insert(Note n)
        {
            entities.AddToNotes(n);
        }

        public void Delete(Note n)
        {
            entities.Notes.DeleteObject(n);
        }

        public void Save()
        {
            entities.SaveChanges();
        }

        public void Dispose()
        {
            entities.Dispose();
        }
    }
}
